#include "Task_start.h"
#include <rtthread.h>
uint8_t led_status = 0x80;
#if defined (FREERTOS)
TaskHandle_t Hd_Task_Start;
#else
static rt_thread_t Task_START_thread =RT_NULL;
#endif
void Task_START(void *param)
{
    LOG_INFO("Task Sart");
	ExtPort_Init();
//	bsp_timer6_counter_init();
//	bsp_timer6_timer_1ms_init();
//	bsp_mco_init(0,0);
	bsp_i2c_init(I2C1_UNIT,100000);
	TCA9539_CFG(0,0);
//	bsp_timerA_timer_1ms_init();
//	bsp_timerA_counter_init();
//    bsp_timer0_init_interrupt();
	bsp_gpio_init();
    bsp_get_chipinfo();
//    bsp_adc_init();
//    Task_RTT_VIEWER_Start();
//    Task_Crypto_Start();
    bsp_uart1_init();
    bsp_exmc_sdram_init();
//    User_FFT_Test();
    bsp_swdt_init();
    bsp_wdt_init();
    while(1)
    {
        bsp_feed_wdt();
        bsp_feed_swdt();
        bsp_start_convert();
		bsp_led_toggle();
		ledcontrol(led_status);//
        led_status = led_status>>1;
        bsp_usart_transfer_wait(M4_USART1,&led_status,1);
        if(led_status<0x20)
        {
            led_status = 0x80;
        }
#if defined (FREERTOS)        
		vTaskDelay(1000/portTICK_PERIOD_MS);
#endif        
    }
}
#if defined (FREERTOS)
void Start_Task_Create(void)
{
	xTaskCreate(Task_START,(const char *)"LED", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+3, &Hd_Task_Start );		    
    vTaskStartScheduler();
}
#else
void Start_Task_Create(void)
{
//	Task_START_thread = rt_thread_create("Task_START",Task_START, RT_NULL, 512, 3, 20 );		    
//    rt_thread_startup (Task_START_thread);
}
void Start_Task_stop(void)
{
//    rt_thread_suspend(Task_START_thread);
}
void Start_Task_resume(void)
{
//    rt_thread_resume(Task_START_thread);
}
void Start_Task_del(void)
{
//    rt_thread_delete(Task_START_thread);
}
#endif
